package com.limao.DBProvider;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import com.limao.DBDataClass.SysVipLevelDataClass;
import com.limao.DbConnection.DbConnectionManager;
import com.limao.Tool.CacheClass;

public class SysVipLevelProvider {


	private static class DB_SysVipLevelProviderContainer {
		private static SysVipLevelProvider instance = new SysVipLevelProvider();
	}

	public static SysVipLevelProvider getInstance() {
		return DB_SysVipLevelProviderContainer.instance;
	}

	// 定义系统表的name与操作语句

	private static final String sys_VipLevel_LOAD1 = "SELECT * FROM cd_sys_viplevel order by vip  ";
	private static final String sys_VipLevel_LOAD2 = "SELECT * FROM cd_sys_viplevel WHERE vip=? ";


	// 初始化
	private SysVipLevelProvider() {

	}

	// lz_sys_category
	public ArrayList<SysVipLevelDataClass> load_sys_VipLevel_all() {
		ArrayList<SysVipLevelDataClass> tmpInfo = new ArrayList<SysVipLevelDataClass>();
		SysVipLevelDataClass tmp = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			con = DbConnectionManager.getConnection();
			pstmt = con.prepareStatement(sys_VipLevel_LOAD1);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				tmp = new SysVipLevelDataClass();
				tmp.vip = rs.getInt(1) + "";
				tmp.value = rs.getInt(2)+"";
				tmp.about = rs.getString(3);
				tmpInfo.add(tmp);
			}

		} catch (Exception e) {
			tmp = null;
		} finally {
			DbConnectionManager.closeConnection(rs, pstmt, con);
		}
		return tmpInfo;
	}



	public SysVipLevelDataClass load_sys_VipLevel(String id) {
		SysVipLevelDataClass tmp = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			con = DbConnectionManager.getConnection();
			pstmt = con.prepareStatement(sys_VipLevel_LOAD2);
			pstmt.setInt(1, CacheClass.getIntValue(id));
			rs = pstmt.executeQuery();
			if (rs.next()) {
				tmp = new SysVipLevelDataClass();
				tmp.vip = rs.getInt(1) + "";
				tmp.value = rs.getInt(2)+"";
				tmp.about = rs.getString(3);
			}

		} catch (Exception e) {
			tmp = null;
		} finally {
			DbConnectionManager.closeConnection(rs, pstmt, con);
		}
		return tmp;
	}
	
}
